package com.zoe.thread.th11_线程池;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author Zoe
 * @Date: 2021/05/05
 * @Description 一个池子中只有一个线程
 */
public class MyThreadDemo_newSingleThreadExecutor {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        try {
            for (int i = 0; i < 5; i++) {
                executorService.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "执行任务");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorService.shutdown();
        }
    }
}
